package com.tank.jdk8.stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created with IntelliJ IDEA.
 * User: SuQiEr
 * Date:2017/1/29
 * Time: 16:30
 * To change this template use File | Settings | File Templates.
 */
public class StreamTest2 {

    public static void main(String[] args) {


        Stream<String> stringStream =Stream.of("123","234","345");
       // String[] stringArray = stringStream.toArray(length -> new String[length]);
        //String[] stringArray = stringStream.toArray(String[]::new);

        //stream -> list
     // List<String> list=  stringStream.collect(Collectors.toList());

//        List<String> list = stringStream.collect(  () -> new ArrayList(),
//                                                    (accumulatorList,item) -> accumulatorList.add(item),
//                                                    (combinerList,accumulatorList) -> combinerList.addAll(accumulatorList));
        //换成LinkList
//        LinkedList<String> list = stringStream.collect(  () -> new LinkedList(),
//                                                    (accumulatorList,item) -> accumulatorList.add(item),
//                                                    (combinerList,accumulatorList) -> combinerList.addAll(accumulatorList));

        //换成方法引用 第一个参数为调用该方法的对象，第二个参数为该方法参数
//        LinkedList<String> list = stringStream.collect(  LinkedList::new,LinkedList::add,LinkedList::addAll);
//
//        list.forEach(System.out::println);

        //转换为字符串拼接

        //String singleString = stringStream.collect(StringBuilder::new,StringBuilder::append,StringBuilder::append).toString();
        String singleString = stringStream.collect(Collectors.joining());
        System.out.println(singleString);
    }
}

